package javacourse.mq.activemq.activemq;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;

/**
 * Create by chenhd on 2021/10/31.
 */
@Service
public class Producer {
    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;

    public void sendQueueMsg(String destinationName, String message) {
        System.out.println("---------------发送queue消息:" + message);
        Destination destination = new ActiveMQQueue(destinationName);
        jmsMessagingTemplate.convertAndSend(destination, message);
    }

    public void sendTopicMsg(String destinationName, String message) {
        System.out.println("---------------发送topic消息:" + message);
        Destination destination = new ActiveMQTopic(destinationName);
        jmsMessagingTemplate.convertAndSend(destination, message);
    }
}
